
import Vue from 'vue'
import VueRouter from 'vue-router'
import document from '@/views/sj/document'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: '登录',
    component: () => import(/* webpackChunkName: "about" */ '../components/Login.vue')
  },
  {
    path: '/home',
    name: '首页',
    component: () => import(/* webpackChunkName: "about" */ '../views/common/ManageView.vue'),
    children: [
      {
        path: 'document',
        component: document,
        children: [
          { path: '/', name: '未上网', component: () => import('../views/sj/docM/not_online') },
          { path: 'online', name: '已上网', component: () => import('../views/sj/docM/online') },
          { path: 'completion_status', name: '已上网', component: () => import('../views/sj/docM/completion_status') },
          { path: 'conclude', name: '已上网', component: () => import('../views/sj/docM/conclude') }
        ]
      }
    ],
    redirect: '/home/account'
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

Vue.use(VueRouter)
// 解决报错
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
// push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}

export function resetRouter () {
  router.matcher = new VueRouter({
    mode: 'history',
    routes: []
  }).matcher
}

router.afterEach((to, from) => {
  document.title = to.name
})
export default router
